package com.wcfsy.wechat.wx.um.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wcfsy.wechat.wx.pagination.IPage;
import com.wcfsy.wechat.wx.pagination.impl.Page;
import com.wcfsy.wechat.wx.um.dao.IUserConDao;
import com.wcfsy.wechat.wx.um.entity.Role;
import com.wcfsy.wechat.wx.um.entity.User;
import com.wcfsy.wechat.wx.um.service.IUserConService;
import com.wcfsy.wechat.wx.util.MD5;

@Service
public class UserConServiceImpl implements IUserConService {
	@Autowired
	private IUserConDao userConDao;

	public void add(User user) {
		try {
			String password = MD5.encode(user.getUserName());
			user.setPassword(password);
			user.setCreateDate(new Date());
			userConDao.add(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		System.out.println(MD5.encode("123456"));
	}

	public void addUserAndRole(User paramUser, List<Long> paramList) {
		// TODO Auto-generated method stub

	}

	public void deleteById(long id) {
		try {
			userConDao.deleteById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void update(User paramUser) {
		try {
			userConDao.update(paramUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void updateStatus(User paramUser) {
		// TODO Auto-generated method stub

	}

	public void updateUserOrg(User paramUser) {
		// TODO Auto-generated method stub

	}

	public User getById(long id) {
		return userConDao.getById(id);
	}

	public User getByUserName(String userName) {
		return userConDao.getByUserName(userName);
	}

	public IPage<User> findByParam(Map<String, Object> paramMap, int index,
			int size) {
		paramMap.put("index", index);
		paramMap.put("size", size);
		IPage<User> page = new Page<User>(userConDao.findByParam(paramMap),
				userConDao.count(paramMap), index, size);
		return page;
	}

	public IPage<User> findAll(int paramInt1, int paramInt2) {
		// TODO Auto-generated method stub
		return null;
	}

	public void changePwd(User user, String password) {
		user.setPassword(password);
		userConDao.changePwd(user);
	}

	public List<Role> getRoleListByUserId(long paramLong) {
		// TODO Auto-generated method stub
		return null;
	}

	public void manageRole(long paramLong1, long paramLong2) {
		// TODO Auto-generated method stub

	}

	public void manageRoleList(User paramUser, List<Long> paramList) {
		// TODO Auto-generated method stub

	}

	public void resetPwd(String userName) {
		String password = MD5.encode(userName);
		User user = getByUserName(userName);
		user.setUpdateDate(new Date());
		changePwd(user, password);
	}

	public boolean checkPermiscard(String paramString, long paramLong) {
		// TODO Auto-generated method stub
		return false;
	}

	public void login(Map paramMap) {
		// TODO Auto-generated method stub

	}

	public User queryUserByCardId(long paramLong) {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean checkUnLock(String paramString1, String paramString2) {
		// TODO Auto-generated method stub
		return false;
	}

}
